package org.hawk.gwtppc.webtest.tests.classsuite;

import org.hawk.gwtppc.webtest.common.Asserts;
import org.hawk.gwtppc.webtest.common.Test;
import org.hawk.gwtppc.webtest.tests.mock.AnnotationMock;
import org.hawk.gwtppc.webtest.tests.mock.ClassMock;
import org.hawk.gwtppc.webtest.tests.mock.EnumMock;
import org.hawk.gwtppc.webtest.tests.mock.InterfaceMock;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock1;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock2;
import org.hawk.gwtppc.webtest.tests.mock.SubClassMock3;

public class NewInstanceTest implements Test {

	public void run() throws Throwable {
		SubClassMock1 mock = SubClassMock1.class.newInstance();
		Asserts.assertTrue(mock != null);
		Asserts.assertTrue(mock instanceof SubClassMock1);
		try {
			AnnotationMock.class.newInstance();
			Asserts.fail("Class is not available for instantiation");
		} catch (InstantiationException ex) {
		}
		try {
			InterfaceMock.class.newInstance();
			Asserts.fail("Class is not available for instantiation");
		} catch (InstantiationException ex) {
		}
		try {
			ClassMock.class.newInstance();
			Asserts.fail("Class is not available for instantiation");
		} catch (InstantiationException ex) {
		}
		try {
			EnumMock.class.newInstance();
			Asserts.fail("Class is not available for instantiation");
		} catch (InstantiationException ex) {
		}
		try {
			SubClassMock2.class.newInstance();
			Asserts.fail("No default constructor available");
		} catch (InstantiationException ex) {
		}
		try {
			SubClassMock3.class.newInstance();
			Asserts.fail("Constructor is not accessed from this package");
		} catch (IllegalAccessException ex) {
		}
	}

	public String getName() {
		return "newInstance()";
	}

}
